﻿@model ShoppingCartModel.DiscountBoxModel
@if (Model.Display)
{
    <div class="coupon-box">
        <div class="title">
            <strong>@T("ShoppingCart.DiscountCouponCode")</strong>
        </div>
        <div class="hint">
            @T("ShoppingCart.DiscountCouponCode.Tooltip")
        </div>
        <div class="coupon-code">
            <input name="discountcouponcode" id="discountcouponcode" type="text" class="discount-coupon-code" aria-label="@T("ShoppingCart.DiscountCouponCode.Label")"/>
            <input type="submit" name="applydiscountcouponcode" id="applydiscountcouponcode" 
                   value="@T("ShoppingCart.DiscountCouponCode.Button")" class="button-2 apply-discount-coupon-code-button" />
        </div>
        @foreach (var message in Model.Messages)
        {
            <div class="@(Model.IsApplied ? "message-success" : "message-failure")">
                @message
            </div>
        }
        @foreach (var discount in Model.AppliedDiscountsWithCodes)
        {
            <div class="current-code">
                <span class="applied-discount-code">@string.Format(T("ShoppingCart.DiscountCouponCode.CurrentCode").Text, discount.CouponCode)</span>
                @*empty value (little hack for FormValueExistsAttribute)*@
                <input type="submit" name="removediscount-@discount.Id" value=" " title="@T("Common.Remove")" class="remove-discount-button" />
            </div>
        }
    </div>
    <script asp-location="Footer">
        $(document).ready(function () {
            $('#discountcouponcode').on('keydown', function (event) {
                if (event.keyCode == 13) {
                    $('#applydiscountcouponcode').trigger("click");
                    return false;
                }
            });
        });
    </script>
}